// cQPSelectDiscussionsPage.cpp : implementation file
//

#include "stdafx.h"
#include "qpmig.h"
#include "cQPSelectDiscussionsPage.h"
#include "helper.h"
#include "cNotesFolderInfo.h"
extern CQPMigApp theApp;

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// cQPSelectDiscussionsPage property page

IMPLEMENT_DYNCREATE(cQPSelectDiscussionsPage, CPropertyPageEx)

cQPSelectDiscussionsPage::cQPSelectDiscussionsPage() : CPropertyPageEx(cQPSelectDiscussionsPage::IDD,0, IDS_QPSELECTDISCITEMSHEADERTITLE, IDS_QPSELECTDOCITEMSHEADERSUBTITLE)
{
	//{{AFX_DATA_INIT(cQPSelectDiscussionsPage)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_bBeenHere=FALSE;
	m_bSpecifyDateRange = FALSE;
	m_codtThreshHold = COleDateTime::GetCurrentTime();

}

cQPSelectDiscussionsPage::~cQPSelectDiscussionsPage()
{
}

void cQPSelectDiscussionsPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(cQPSelectDiscussionsPage)
	DDX_Control(pDX, IDC_DATETIMEPICKER1, m_ctrDateTime);
	DDX_Control(pDX, IDC_LIST1, m_lbItems);
	DDX_Check(pDX, IDC_CHECK1, m_bSpecifyDateRange);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_codtThreshHold);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(cQPSelectDiscussionsPage, CPropertyPageEx)
	//{{AFX_MSG_MAP(cQPSelectDiscussionsPage)
	ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
	ON_LBN_DBLCLK(IDC_LIST1, OnDblclkList1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// cQPSelectDiscussionsPage message handlers

LRESULT cQPSelectDiscussionsPage::OnWizardNext() 
{
	UpdateData(TRUE);
	DWORD dwErrCode=0;
	theApp.stControl.codtDiscussionThreshold=m_codtThreshHold ;
	theApp.stControl.bUseDiscussionThreshold=m_bSpecifyDateRange ;

	for(int i=0;i<m_lbItems.GetCount();i++)
		{
			if(m_lbItems.GetSel(i))
				{
					cNotesFolderInfo *pFolderInfo=(cNotesFolderInfo *)m_lbItems.GetItemDataPtr(i);
					if(pFolderInfo)
						{
							pFolderInfo->b_Transfer=TRUE;
							pFolderInfo->m_wType=DISCFOLDER;

						}
				};
		}
	

	return CPropertyPageEx::OnWizardNext();
}

BOOL cQPSelectDiscussionsPage::OnSetActive() 
{
	CPropertySheet* psheet = (CPropertySheet*) GetParent();   
	psheet->SetWizardButtons(PSWIZB_BACK | PSWIZB_NEXT);
	if(m_bBeenHere)
		{
			CPropertyPageEx::OnSetActive();
		}
	m_lbItems.ResetContent();

	m_bBeenHere=TRUE;
	for(int i=0;i<=theApp.stControl.pdb->cobjNotesFolders.GetUpperBound();i++)
		{
			cNotesFolderInfo *pFolderInfo=(cNotesFolderInfo *)theApp.stControl.pdb->cobjNotesFolders.GetAt(i);
			if(pFolderInfo)
				{
					if(pFolderInfo->m_wType==NODEFFOLDER || pFolderInfo->m_wType==DISCFOLDER)
						{
							int id=m_lbItems.AddString(pFolderInfo->m_strFolderDisplayName);
							if(LB_ERR!=id)
								{
									m_lbItems.SetItemDataPtr(id,pFolderInfo);
									if(pFolderInfo->m_wType==DISCFOLDER && pFolderInfo->b_Transfer)
										m_lbItems.SetSel(id);
								}
						}


				}
			
		}
	
	return CPropertyPageEx::OnSetActive();
}
void cQPSelectDiscussionsPage::OnCheck1() 
{
	UpdateData(TRUE);
	if(m_bSpecifyDateRange)
		{
			m_ctrDateTime.ShowWindow(SW_NORMAL);
		}
	else
		{
			m_ctrDateTime.ShowWindow(SW_HIDE);
		}


}

void cQPSelectDiscussionsPage::OnDblclkList1() 
{
	int nPage;
	CPropertySheet* psheet = (CPropertySheet*) GetParent();   
	if(psheet)
		{
			nPage=psheet->GetActiveIndex();
			if(OnWizardNext()>=0)
				psheet->SetActivePage(nPage+1);
		}
	
}
